package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 通用异常处理类
 * @作者 itcast
 * @创建日期 2020/9/22 9:09
 **/
@ControllerAdvice
@Log4j2
public class ExceptionCatch {

    @ExceptionHandler
    @ResponseBody
    public ResponseResult exception(Exception exception){
        exception.printStackTrace();
        log.error("catch exception: {}   cause: {}",exception.getMessage(),exception.getCause());
        // 返回通用异常
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR);
    }

}
